package test.ygqh.baby.service;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.foxinmy.weixin4j.util.StringUtil;

public class test1 {
	public static String BASEINFO = "Mr.Y";
	public static final int COUNT = 2000000;

	/**
	 * 执行一项String赋值测试
	 */
	public static void doStringTest() {

		String str = new String(BASEINFO);
		long starttime = System.currentTimeMillis();
		for (int i = 0; i < COUNT / 100; i++) {
			str = str + "miss";
		}
		long endtime = System.currentTimeMillis();
		System.out.println((endtime - starttime) + " millis has costed when used String.");
	}

	/**
	 * 执行一项StringBuffer赋值测试
	 */
	public static void doStringBufferTest() {

		StringBuffer sb = new StringBuffer(BASEINFO);
		long starttime = System.currentTimeMillis();
		for (int i = 0; i < COUNT; i++) {
			sb = sb.append("miss");
		}
		long endtime = System.currentTimeMillis();
		System.out.println((endtime - starttime) + " millis has costed when used StringBuffer.");
	}

	/**
	 * 执行一项StringBuilder赋值测试
	 */
	public static void doStringBuilderTest() {

		StringBuilder sb = new StringBuilder(BASEINFO);
		long starttime = System.currentTimeMillis();
		for (int i = 0; i < COUNT; i++) {
			sb = sb.append("miss");
		}
		long endtime = System.currentTimeMillis();
		System.out.println((endtime - starttime) + " millis has costed when used StringBuilder.");
	}

	/**
	 * 测试StringBuffer遍历赋值结果
	 * 
	 * @param mlist
	 */
	public static void doStringBufferListTest(List<String> mlist) {
		StringBuffer sb = new StringBuffer();
		long starttime = System.currentTimeMillis();
		for (String string : mlist) {
			sb.append(string);
		}
		long endtime = System.currentTimeMillis();
		System.out.println(sb.toString() + "buffer cost:" + (endtime - starttime) + " millis");
	}

	/**
	 * 测试StringBuilder迭代赋值结果
	 * 
	 * @param mlist
	 */
	public static void doStringBuilderListTest(List<String> mlist) {
		StringBuilder sb = new StringBuilder();
		long starttime = System.currentTimeMillis();
		for (Iterator<String> iterator = mlist.iterator(); iterator.hasNext();) {
			sb.append(iterator.next());
		}

		long endtime = System.currentTimeMillis();
		System.out.println(sb.toString() + "builder cost:" + (endtime - starttime) + " millis");
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
    	StringBuilder buf = new StringBuilder();
    	if(StringUtil.isBlank(buf.toString())){
    		
    		System.out.println(111);
    	}
    	System.out.println(buf.toString());
    	System.out.println(2);
	}
}
